<?php
	class model_question extends CI_Model{
		protected $_table = "tbl_questions";
		protected $_category = "tbl_category";
		protected $_categorie = "tbl_categorie";
		public function __construct(){
			parent::__construct();
		}
		public function listall($off,$start){
			$this->db->order_by("id","DESC");
			$this->db->limit($off,$start);
			$this->db->join('tbl_category','tbl_category.cid = tbl_questions.cateid');
			return $this->db->get($this->_table)->result_array();
		}
		public function countall(){
			$this->db->join('tbl_category','tbl_category.cid = tbl_questions.cateid');
			return $this->db->count_all_results($this->_table);
		}
		public function listcate(){
			return $this->db->get($this->_category)->result_array();
		}
		public function listcago($cateid){
			$this->db->where("cateid",$cateid);
			return $this->db->get($this->_categorie)->result_array();
		}
		public function add($data){
			$this->db->insert($this->_table,$data);
		}
		public function getdata($id){
			$this->db->where("id",$id);
			return $this->db->get($this->_table)->row_array();
		}
		public function update($id,$data){
			$this->db->where("id",$id);
			return $this->db->update($this->_table,$data);
		}
		public function del($id){
			$this->db->where("id",$id);
			return $this->db->delete($this->_table);
		}
	}